//
//  ZLSwipeableViewController.m
//  SDKSample
//
//  Created by 小肥羊 on 16/1/4.
//  Copyright © 2016年 Zhu‘s Game House. All rights reserved.
//

#import "ZLSwipeableViewController.h"

@interface ZLSwipeableViewController () <ZLSwipeableViewDataSource, ZLSwipeableViewDelegate>

//@property (nonatomic, strong) ZLSwipeableView *swipeableView;

@end

@implementation ZLSwipeableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.swipeableView.numberOfActiveViews = 4;
    
    // Required Data Source
    self.swipeableView.dataSource = self;
    
    // Optional Delegate
    self.swipeableView.delegate = self;
    
    self.swipeableView.translatesAutoresizingMaskIntoConstraints = NO;

}

- (void)viewDidLayoutSubviews {
    [self.swipeableView loadViewsIfNeeded];
}

#pragma mark - ZLSwipeableViewDelegate

- (void)swipeableView:(ZLSwipeableView *)swipeableView
         didSwipeView:(UIView *)view
          inDirection:(ZLSwipeableViewDirection)direction {
    NSLog(@"did swipe in direction: %zd", direction);
}

- (void)swipeableView:(ZLSwipeableView *)swipeableView didCancelSwipe:(UIView *)view {
    NSLog(@"did cancel swipe");
}

- (void)swipeableView:(ZLSwipeableView *)swipeableView
  didStartSwipingView:(UIView *)view
           atLocation:(CGPoint)location {
    NSLog(@"did start swiping at location: x %f, y %f", location.x, location.y);
}

- (void)swipeableView:(ZLSwipeableView *)swipeableView
          swipingView:(UIView *)view
           atLocation:(CGPoint)location
          translation:(CGPoint)translation {
    NSLog(@"swiping at location: x %f, y %f, translation: x %f, y %f", location.x, location.y,
          translation.x, translation.y);
}

- (void)swipeableView:(ZLSwipeableView *)swipeableView
    didEndSwipingView:(UIView *)view
           atLocation:(CGPoint)location {
    NSLog(@"did end swiping at location: x %f, y %f", location.x, location.y);
}

#pragma mark - ZLSwipeableViewDataSource

- (UIView *)nextViewForSwipeableView:(ZLSwipeableView *)swipeableView {
//    if (self.colorIndex >= self.colors.count) {
//        self.colorIndex = 0;
//    }
    
    CardView *view = [[CardView alloc] initWithFrame:swipeableView.bounds];
    view.backgroundColor = [UIColor redColor];
//    view.backgroundColor = [self colorForName:self.colors[self.colorIndex]];
//    self.colorIndex++;
    
//    if (self.loadCardFromXib) {
//        UIView *contentView =
//        [[NSBundle mainBundle] loadNibNamed:@"CardContentView" owner:self options:nil][0];
//        contentView.translatesAutoresizingMaskIntoConstraints = NO;
//        [view addSubview:contentView];
//        
//        // This is important:
//        // https://github.com/zhxnlai/ZLSwipeableView/issues/9
//        NSDictionary *metrics =
//        @{ @"height" : @(view.bounds.size.height),
//           @"width" : @(view.bounds.size.width) };
//        NSDictionary *views = NSDictionaryOfVariableBindings(contentView);
//        [view addConstraints:[NSLayoutConstraint
//                              constraintsWithVisualFormat:@"H:|[contentView(width)]"
//                              options:0
//                              metrics:metrics
//                              views:views]];
//        [view addConstraints:[NSLayoutConstraint
//                              constraintsWithVisualFormat:@"V:|[contentView(height)]"
//                              options:0
//                              metrics:metrics
//                              views:views]];
//    }
    return view;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
